<!DOCTYPE html>
<html lang=zh>
<head>
  <meta charset="utf-8">
  
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui">
  <meta name="renderer" content="webkit">
  <meta http-equiv="Cache-Control" content="no-transform" />
  <meta http-equiv="Cache-Control" content="no-siteapp" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="format-detection" content="telephone=no,email=no,adress=no">
  <!-- Color theme for statusbar -->
  <meta name="theme-color" content="#000000" />
  <!-- 强制页面在当前窗口以独立页面显示,防止别人在框架里调用页面 -->
  <meta http-equiv="window-target" content="_top" />
  
  
  <title>使用 Redis Lua脚本设置和获取多维度数据缓存(PHP示例) | 知识是最有价值的东西</title>
  <meta name="description" content="场景分析 在我们日常项目开发中，是否会经常遇到同一份数据需要多个维度查询的需求，这个需求实现起来并不难，实现方法也有很多种，但每一种都有各自的利弊，下面就以下三种方案做一个分析  实现方案1、缓存数据冗余 缓存数据冗余，是指同一份数据，多个查询维度的 key 分别缓存一份数据 优点：缓存数据相互独立，一次查询请求即可获取缓存数据，缓存生命周期可分别定义 缺点：同一份数据多份冗余，带来存储资源的浪费">
<meta property="og:type" content="article">
<meta property="og:title" content="使用 Redis Lua脚本设置和获取多维度数据缓存(PHP示例)">
<meta property="og:url" content="http:&#x2F;&#x2F;jirenyou.gitee.io&#x2F;blog&#x2F;2019&#x2F;12&#x2F;21&#x2F;php&#x2F;php-redis-lua&#x2F;index.html">
<meta property="og:site_name" content="知识是最有价值的东西">
<meta property="og:description" content="场景分析 在我们日常项目开发中，是否会经常遇到同一份数据需要多个维度查询的需求，这个需求实现起来并不难，实现方法也有很多种，但每一种都有各自的利弊，下面就以下三种方案做一个分析  实现方案1、缓存数据冗余 缓存数据冗余，是指同一份数据，多个查询维度的 key 分别缓存一份数据 优点：缓存数据相互独立，一次查询请求即可获取缓存数据，缓存生命周期可分别定义 缺点：同一份数据多份冗余，带来存储资源的浪费">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2019-12-21T15:40:15.000Z">
<meta property="article:modified_time" content="2019-12-21T15:40:15.000Z">
<meta property="article:author" content="Jirry">
<meta property="article:tag" content="redis">
<meta property="article:tag" content="redis lua脚本">
<meta name="twitter:card" content="summary">
  <!-- Canonical links -->
  <link rel="canonical" href="http://jirenyou.gitee.io/blog/2019/12/21/php/php-redis-lua/index.html">
  
    <link rel="alternate" href="/atom.xml" title="知识是最有价值的东西" type="application/atom+xml">
  
  
    <link rel="icon" href="/blog/favicon.ico" type="image/x-icon">
  
  
<link rel="stylesheet" href="/blog/css/style.css">

  
  
  
  
<meta name="generator" content="Hexo 4.1.0"></head>


<body class="main-center theme-black" itemscope itemtype="http://schema.org/WebPage">
  <header class="header" itemscope itemtype="http://schema.org/WPHeader">
  <div class="slimContent">
    <div class="navbar-header">
      
      
      <div class="profile-block text-center">
        <a id="avatar" href="https://jirenyou.gitee.io/blog" target="_blank">
          <img class="img-circle img-rotate" src="/blog/images/avatar.jpg" width="200" height="200">
        </a>
        <h2 id="name" class="hidden-xs hidden-sm">Jirry</h2>
        <h3 id="title" class="hidden-xs hidden-sm hidden-md">Back end development Architecture</h3>
        <small id="location" class="text-muted hidden-xs hidden-sm"><i class="icon icon-map-marker"></i> Shenzhen, China</small>
      </div>
      
      <div class="search" id="search-form-wrap">

    <form class="search-form sidebar-form">
        <div class="input-group">
            <input type="text" class="search-form-input form-control" placeholder="搜索" />
            <span class="input-group-btn">
                <button type="submit" class="search-form-submit btn btn-flat" onclick="return false;"><i class="icon icon-search"></i></button>
            </span>
        </div>
    </form>
    <div class="ins-search">
  <div class="ins-search-mask"></div>
  <div class="ins-search-container">
    <div class="ins-input-wrapper">
      <input type="text" class="ins-search-input" placeholder="想要查找什么..." x-webkit-speech />
      <button type="button" class="close ins-close ins-selectable" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
    </div>
    <div class="ins-section-wrapper">
      <div class="ins-section-container"></div>
    </div>
  </div>
</div>


</div>
      <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target="#main-navbar" aria-controls="main-navbar" aria-expanded="false">
        <span class="sr-only">Toggle navigation</span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
    </div>
    <nav id="main-navbar" class="collapse navbar-collapse" itemscope itemtype="http://schema.org/SiteNavigationElement" role="navigation">
      <ul class="nav navbar-nav main-nav ">
        
        
        <li class="menu-item menu-item-home">
          <a href="/blog/.">
            
            <i class="icon icon-home-fill"></i>
            
            <span class="menu-title">首页</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives">
            
            <i class="icon icon-archives-fill"></i>
            
            <span class="menu-title">归档</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories">
            
            <i class="icon icon-folder"></i>
            
            <span class="menu-title">分类</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags">
            
            <i class="icon icon-tags"></i>
            
            <span class="menu-title">标签</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-repository">
          <a href="/blog/repository">
            
            <i class="icon icon-project"></i>
            
            <span class="menu-title">项目</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-links">
          <a href="/blog/links">
            
            <i class="icon icon-friendship"></i>
            
            <span class="menu-title">友链</span>
          </a>
        </li>
        
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about">
            
            <i class="icon icon-cup-fill"></i>
            
            <span class="menu-title">关于</span>
          </a>
        </li>
        
      </ul>
      
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/jirryji" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="https://weibo.com/7355950025" target="_blank" title="Weibo" data-toggle=tooltip data-placement=top><i class="icon icon-weibo"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    </nav>
  </div>
</header>

  
    <aside class="sidebar" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    
      <div class="widget">
    <h3 class="widget-title">公告</h3>
    <div class="widget-body">
        <div id="board">
            <div class="content">
                <p>欢迎交流与分享经验!</p>
            </div>
        </div>
    </div>
</div>

    
      
  <div class="widget">
    <h3 class="widget-title">分类</h3>
    <div class="widget-body">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/docker/">docker</a><span class="category-list-count">4</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/elasticsearch/">elasticsearch</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/java/">java</a><span class="category-list-count">9</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/php/">php</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/">版本控制</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E8%AF%AD%E6%B3%95/">语法</a><span class="category-list-count">1</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/blog/categories/%E8%AF%AD%E6%B3%95/markdown-%E8%AF%AD%E6%B3%95/">markdown 语法</a><span class="category-list-count">1</span></li></ul></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签</h3>
    <div class="widget-body">
      <ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/aop/" rel="tag">aop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/bloom-filter/" rel="tag">bloom-filter</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/busybox/" rel="tag">busybox</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/docker/" rel="tag">docker</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/elasticsearch/" rel="tag">elasticsearch</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/es/" rel="tag">es</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/filter/" rel="tag">filter</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/git/" rel="tag">git</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/hashMap/" rel="tag">hashMap</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/idea/" rel="tag">idea</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/interceptor/" rel="tag">interceptor</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/iterator/" rel="tag">iterator</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/java/" rel="tag">java</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/localDateTime/" rel="tag">localDateTime</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/map/" rel="tag">map</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/markdown/" rel="tag">markdown</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/maven/" rel="tag">maven</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/redis/" rel="tag">redis</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/redis-lua%E8%84%9A%E6%9C%AC/" rel="tag">redis lua脚本</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/blog/tags/volumes/" rel="tag">volumes</a><span class="tag-list-count">1</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">标签云</h3>
    <div class="widget-body tagcloud">
      <a href="/blog/tags/aop/" style="font-size: 13px;">aop</a> <a href="/blog/tags/bloom-filter/" style="font-size: 13px;">bloom-filter</a> <a href="/blog/tags/busybox/" style="font-size: 13px;">busybox</a> <a href="/blog/tags/docker/" style="font-size: 14px;">docker</a> <a href="/blog/tags/elasticsearch/" style="font-size: 13.67px;">elasticsearch</a> <a href="/blog/tags/es/" style="font-size: 13px;">es</a> <a href="/blog/tags/filter/" style="font-size: 13.33px;">filter</a> <a href="/blog/tags/git/" style="font-size: 13.33px;">git</a> <a href="/blog/tags/hashMap/" style="font-size: 13px;">hashMap</a> <a href="/blog/tags/idea/" style="font-size: 13px;">idea</a> <a href="/blog/tags/interceptor/" style="font-size: 13px;">interceptor</a> <a href="/blog/tags/iterator/" style="font-size: 13px;">iterator</a> <a href="/blog/tags/java/" style="font-size: 13.67px;">java</a> <a href="/blog/tags/localDateTime/" style="font-size: 13px;">localDateTime</a> <a href="/blog/tags/map/" style="font-size: 13px;">map</a> <a href="/blog/tags/markdown/" style="font-size: 13px;">markdown</a> <a href="/blog/tags/maven/" style="font-size: 13.67px;">maven</a> <a href="/blog/tags/redis/" style="font-size: 13px;">redis</a> <a href="/blog/tags/redis-lua%E8%84%9A%E6%9C%AC/" style="font-size: 13px;">redis lua脚本</a> <a href="/blog/tags/volumes/" style="font-size: 13px;">volumes</a>
    </div>
  </div>

    
      
  <div class="widget">
    <h3 class="widget-title">归档</h3>
    <div class="widget-body">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2020/01/">一月 2020</a><span class="archive-list-count">9</span></li><li class="archive-list-item"><a class="archive-list-link" href="/blog/archives/2019/12/">十二月 2019</a><span class="archive-list-count">11</span></li></ul>
    </div>
  </div>


    
      
  <div class="widget">
    <h3 class="widget-title">最新文章</h3>
    <div class="widget-body">
      <ul class="recent-post-list list-unstyled no-thumbnail">
        
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/14/java/maven/mvn-private-repo/" class="title">Maven私服（Nexus）搭建</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-14T13:37:39.000Z" itemprop="datePublished">2020-01-14</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-idea-start-slow/" class="title">解决Idea启动Spring Boot很慢的问题</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T15:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-springboot-filter-in-aop/" class="title">AOP（面向切面编程）、Filter（过虑器）、Interceptor（拦截器）</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T15:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-req-resp/" class="title">HttpServletRequest 与 HttpServletResponse 的实现类</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T08:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
          <li>
            
            <div class="item-inner">
              <p class="item-category">
                <a class="category-link" href="/blog/categories/java/">java</a>
              </p>
              <p class="item-title">
                <a href="/blog/2020/01/09/java/java-springboot-filter/" class="title">Spring Boot 过滤器 Filter</a>
              </p>
              <p class="item-date">
                <time datetime="2020-01-09T08:24:15.000Z" itemprop="datePublished">2020-01-09</time>
              </p>
            </div>
          </li>
          
      </ul>
    </div>
  </div>
  

    
  </div>
</aside>

  
  
<aside class="sidebar sidebar-toc collapse" id="collapseToc" itemscope itemtype="http://schema.org/WPSideBar">
  <div class="slimContent">
    <nav id="toc" class="article-toc">
      <h3 class="toc-title">文章目录</h3>
      <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#场景分析"><span class="toc-number">1.</span> <span class="toc-text">场景分析</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#实现方案"><span class="toc-number">2.</span> <span class="toc-text">实现方案</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1、缓存数据冗余"><span class="toc-number">2.1.</span> <span class="toc-text">1、缓存数据冗余</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2、缓存数据复用"><span class="toc-number">2.2.</span> <span class="toc-text">2、缓存数据复用</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3、使用-Lua-脚本设置和读取"><span class="toc-number">2.3.</span> <span class="toc-text">3、使用 Lua 脚本设置和读取</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#用户信息缓存类：UserInfoCache-php"><span class="toc-number">2.3.1.</span> <span class="toc-text">用户信息缓存类：UserInfoCache.php</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#设置用户缓存数据-通过手机号：setUserInfoByMobile-lua"><span class="toc-number">2.3.2.</span> <span class="toc-text">设置用户缓存数据 - 通过手机号：setUserInfoByMobile.lua</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#获取用户缓存数据-通过手机号：getUserInfoByMobile-lua"><span class="toc-number">2.3.3.</span> <span class="toc-text">获取用户缓存数据 - 通过手机号：getUserInfoByMobile.lua</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#测试示例：example-php"><span class="toc-number">2.3.4.</span> <span class="toc-text">测试示例：example.php</span></a></li></ol></li></ol></li></ol>
    </nav>
  </div>
</aside>

<main class="main" role="main">
  <div class="content">
  <article id="post-php/php-redis-lua" class="article article-type-post" itemscope itemtype="http://schema.org/BlogPosting">
    
    <div class="article-header">
      
        
  
    <h1 class="article-title" itemprop="name">
      使用 Redis Lua脚本设置和获取多维度数据缓存(PHP示例)
    </h1>
  

      
      <div class="article-meta">
        <span class="article-date">
    <i class="icon icon-calendar-check"></i>
	<a href="/blog/2019/12/21/php/php-redis-lua/" class="article-date">
	  <time datetime="2019-12-21T15:40:15.000Z" itemprop="datePublished">2019-12-21</time>
	</a>
</span>
        
  <span class="article-category">
    <i class="icon icon-folder"></i>
    <a class="article-category-link" href="/blog/categories/php/">php</a>
  </span>

        
  <span class="article-tag">
    <i class="icon icon-tags"></i>
	<a class="article-tag-link" href="/blog/tags/redis/" rel="tag">redis</a>, <a class="article-tag-link" href="/blog/tags/redis-lua%E8%84%9A%E6%9C%AC/" rel="tag">redis lua脚本</a>
  </span>


        
	<span class="article-read hidden-xs">
	    <i class="icon icon-eye-fill" aria-hidden="true"></i>
	    <span id="busuanzi_container_page_pv">
			<span id="busuanzi_value_page_pv">0</span>
		</span>
	</span>


        <span class="post-comment"><i class="icon icon-comment"></i> <a href="/blog/2019/12/21/php/php-redis-lua/#comments" class="article-comment-link">评论</a></span>
        
	
	

      </div>
    </div>
    <div class="article-entry marked-body" itemprop="articleBody">
      
        <h2 id="场景分析"><a href="#场景分析" class="headerlink" title="场景分析"></a>场景分析</h2><blockquote>
<p>在我们日常项目开发中，是否会经常遇到同一份数据需要多个维度查询的需求，这个需求实现起来并不难，实现方法也有很多种，但每一种都有各自的利弊，下面就以下三种方案做一个分析</p>
</blockquote>
<h2 id="实现方案"><a href="#实现方案" class="headerlink" title="实现方案"></a>实现方案</h2><h3 id="1、缓存数据冗余"><a href="#1、缓存数据冗余" class="headerlink" title="1、缓存数据冗余"></a>1、缓存数据冗余</h3><blockquote>
<p>缓存数据冗余，是指同一份数据，多个查询维度的 key 分别缓存一份数据</p>
<p>优点：缓存数据相互独立，一次查询请求即可获取缓存数据，缓存生命周期可分别定义</p>
<p>缺点：同一份数据多份冗余，带来存储资源的浪费，数据发生变更每个维度缓存数据都需要更新</p>
</blockquote>
<h3 id="2、缓存数据复用"><a href="#2、缓存数据复用" class="headerlink" title="2、缓存数据复用"></a>2、缓存数据复用</h3><blockquote>
<p>缓存数据复用，是指多个查看维度的 key 指向同一份缓存数据</p>
<p>优点：缓存数据唯一，节省存储资源，数据发生变更只需要修改一份数据即可</p>
<p>缺点：查询请求次数增加，可能需要通过2次以上查询，才能获取到最终的缓存数据</p>
</blockquote>
<h3 id="3、使用-Lua-脚本设置和读取"><a href="#3、使用-Lua-脚本设置和读取" class="headerlink" title="3、使用 Lua 脚本设置和读取"></a>3、使用 Lua 脚本设置和读取</h3><blockquote>
<p>Redis 执行 lua脚本，下面以用户信息缓存为例，通过用户ID和手机号两个维度查询和设置缓存数据</p>
<p>优点：缓存数据唯一，节省存储资源，没有额外的查询请求</p>
<p>缺点：Redis 服务器需要解析执行Lua脚本程序，增加 Redis 服务器的负载</p>
</blockquote>
<h4 id="用户信息缓存类：UserInfoCache-php"><a href="#用户信息缓存类：UserInfoCache-php" class="headerlink" title="用户信息缓存类：UserInfoCache.php"></a>用户信息缓存类：UserInfoCache.php</h4><figure class="highlight php"><table><tr><td class="code"><pre><span class="line"><span class="comment">/**</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment"> * 用户信息缓存</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment"> * Class UserCache</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment"> */</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">UserInfoCache</span></span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="class"></span>&#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">/**</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * Redis 主机</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@var</span> string</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     */</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="keyword">private</span> $host = <span class="string">'127.0.0.1'</span>;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">/**</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * Redis 主机端口号</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@var</span> int</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     */</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="keyword">private</span> $port = <span class="number">6379</span>;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">/**</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * Redis 认证秘钥</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@var</span> string</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     */</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="keyword">private</span> $auth = <span class="string">''</span>;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">/**</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * Redis 实例</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@var</span> mixed</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     */</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="keyword">private</span> $redis;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">/**</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * 用户ID获取缓存 key 前缀</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@var</span> string</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     */</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="keyword">const</span> PRE_USER_CACHE = <span class="string">'app:user:id_'</span>;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">/**</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * 用户手机号获取缓存 key 前缀</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@var</span> string</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     */</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="keyword">const</span> PRE_MOBILE_USER_CACHE = <span class="string">'app:user:mobile_'</span>;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">/**</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * 初始化Redi实例</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * UserInfoCache constructor.</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@param</span> string      $host Redis 主机地址</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@param</span> int         $port Redis 主机端口</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@param</span> null|string $auth Redis 认证秘钥</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     */</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">__construct</span><span class="params">($host = null, $port = null, $auth = null)</span></span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="function">    </span>&#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="comment">// 创建并连接Redis服务器</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="keyword">$this</span>-&gt;redis = <span class="keyword">new</span> Redis();</span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="keyword">$this</span>-&gt;redis-&gt;connect($host ?: <span class="keyword">$this</span>-&gt;host, $port ?: <span class="keyword">$this</span>-&gt;port);</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="comment">// 身份认证</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="keyword">if</span> ($auth || <span class="keyword">$this</span>-&gt;auth) &#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="keyword">$this</span>-&gt;redis-&gt;auth($auth ?: <span class="keyword">$this</span>-&gt;auth);</span></pre></td></tr><tr><td class="code"><pre><span class="line">        &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line">    &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">/**</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * 获取用户缓存信息</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@param</span> int $userId 用户ID</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@return</span> mixed|null</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     */</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">getUserInfo</span><span class="params">(int $userId)</span></span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="function">    </span>&#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">        $value = <span class="keyword">$this</span>-&gt;redis-&gt;get(<span class="keyword">self</span>::PRE_USER_CACHE . $userId);</span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="keyword">return</span> $value ? json_decode($value, <span class="keyword">true</span>) : <span class="keyword">null</span>;</span></pre></td></tr><tr><td class="code"><pre><span class="line">    &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">/**</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * 设置用户缓存信息</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@param</span> int   $userId   用户ID</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@param</span> array $userInfo 用户信息</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@return</span> bool</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     */</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">setUserInfo</span><span class="params">(int $userId, array $userInfo)</span></span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="function">    </span>&#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">        $value = json_encode($userInfo, JSON_UNESCAPED_UNICODE);</span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;redis-&gt;set(<span class="keyword">self</span>::PRE_USER_CACHE . $userId, $value);</span></pre></td></tr><tr><td class="code"><pre><span class="line">    &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">/**</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * 获取用户缓存信息 - 通过手机号</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@param</span> string $mobile 手机号</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@return</span> mixed</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     */</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">getUserInfoByMobile</span><span class="params">(string $mobile)</span></span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="function">    </span>&#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="comment">// 加载 redis lua 脚本程序</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">        $luaScript = file_get_contents(<span class="string">'./lua/getUserInfoByMobile.lua'</span>);</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="comment">// redis lua 参数</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">        $data = [</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="keyword">self</span>::PRE_MOBILE_USER_CACHE =&gt; $mobile,    <span class="comment">// 手机号缓存 key</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="keyword">self</span>::PRE_USER_CACHE        =&gt; <span class="number">0</span>   <span class="comment">// 用户缓存key（默认：0）</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">        ];</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">        $args = array_merge(array_keys($data), array_values($data));</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="comment">// redis lua 参数数量</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">        $argsCount = count($data);</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="comment">// 获取用户信息</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">        $userInfo = <span class="keyword">$this</span>-&gt;redis-&gt;eval($luaScript, $args, $argsCount);</span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="keyword">return</span> $userInfo ? json_decode($userInfo, <span class="keyword">true</span>) : $userInfo;</span></pre></td></tr><tr><td class="code"><pre><span class="line">    &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="comment">/**</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * 设置用户缓存信息 - 通过手机号</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@param</span> string $mobile   用户手机号</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@param</span> int    $userId   用户ID</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@param</span> array  $userInfo 用户信息</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     *</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     * <span class="doctag">@return</span> bool</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">     */</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="keyword">public</span> <span class="function"><span class="keyword">function</span> <span class="title">setUserInfoByMobile</span><span class="params">(string $mobile, int $userId, array $userInfo)</span></span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="function">    </span>&#123;</span></pre></td></tr><tr><td class="code"><pre><span class="line">        $userInfo = json_encode($userInfo, JSON_UNESCAPED_UNICODE);</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="comment">// 加载 redis lua 脚本程序</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">        $luaScript = file_get_contents(<span class="string">'./lua/setUserInfoByMobile.lua'</span>);</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="comment">// redis lua 参数</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">        $data = [</span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="keyword">self</span>::PRE_USER_CACHE . $userId        =&gt; $userInfo, <span class="comment">// 通过用户ID缓存用户信息</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">            <span class="keyword">self</span>::PRE_MOBILE_USER_CACHE . $mobile =&gt; $userId    <span class="comment">// 设置手机号缓存</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">        ];</span></pre></td></tr><tr><td class="code"><pre><span class="line">        $args = array_merge(array_keys($data), array_values($data));</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="comment">// redis lua 参数数量</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">        $argsCount = count($data);</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">        <span class="keyword">return</span> <span class="keyword">$this</span>-&gt;redis-&gt;eval($luaScript, $args, $argsCount);</span></pre></td></tr><tr><td class="code"><pre><span class="line">    &#125;</span></pre></td></tr><tr><td class="code"><pre><span class="line">&#125;</span></pre></td></tr></table></figure>

<h4 id="设置用户缓存数据-通过手机号：setUserInfoByMobile-lua"><a href="#设置用户缓存数据-通过手机号：setUserInfoByMobile-lua" class="headerlink" title="设置用户缓存数据 - 通过手机号：setUserInfoByMobile.lua"></a>设置用户缓存数据 - 通过手机号：setUserInfoByMobile.lua</h4><figure class="highlight lua"><table><tr><td class="code"><pre><span class="line"><span class="comment">-- 设置用户缓存</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="keyword">local</span> userCache = redis.call(<span class="string">'SET'</span>, KEYS[<span class="number">1</span>], ARGV[<span class="number">1</span>]);</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">-- 设置失败</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="keyword">if</span> <span class="keyword">not</span> userCache <span class="keyword">then</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="keyword">return</span> userCache;</span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="keyword">end</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">-- 设置手机号缓存</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="keyword">return</span> redis.call(<span class="string">'SET'</span>, KEYS[<span class="number">2</span>], ARGV[<span class="number">2</span>]);</span></pre></td></tr></table></figure>

<h4 id="获取用户缓存数据-通过手机号：getUserInfoByMobile-lua"><a href="#获取用户缓存数据-通过手机号：getUserInfoByMobile-lua" class="headerlink" title="获取用户缓存数据 - 通过手机号：getUserInfoByMobile.lua"></a>获取用户缓存数据 - 通过手机号：getUserInfoByMobile.lua</h4><figure class="highlight lua"><table><tr><td class="code"><pre><span class="line"><span class="comment">-- 获取用户ID</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="keyword">local</span> userId = redis.call(<span class="string">'GET'</span>, KEYS[<span class="number">1</span>] .. ARGV[<span class="number">1</span>]);</span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="keyword">if</span> <span class="keyword">not</span> userId <span class="keyword">then</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="keyword">return</span> userId</span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="keyword">end</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">-- 用户缓存 Key：用户缓存Key前缀 .. 用户ID</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="keyword">local</span> userCacheKey = KEYS[<span class="number">2</span>] .. userId;</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">-- 获取用户缓存信息</span></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="keyword">return</span> redis.call(<span class="string">'GET'</span>, userCacheKey);</span></pre></td></tr></table></figure>

<h4 id="测试示例：example-php"><a href="#测试示例：example-php" class="headerlink" title="测试示例：example.php"></a>测试示例：example.php</h4><figure class="highlight php"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 用户信息</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">$userInfo   = [</span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="string">"id"</span>     =&gt; <span class="number">1</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="string">"name"</span>   =&gt; <span class="string">"zhansan"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="string">"email"</span>  =&gt; <span class="string">"zhansan@163.com"</span>,</span></pre></td></tr><tr><td class="code"><pre><span class="line">    <span class="string">"mobile"</span> =&gt; <span class="string">"18166668888"</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">];</span></pre></td></tr><tr><td class="code"><pre><span class="line">$userId     = $userInfo[<span class="string">"id"</span>];</span></pre></td></tr><tr><td class="code"><pre><span class="line">$userMobile = $userInfo[<span class="string">"mobile"</span>];</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">// 用户缓存实例</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">$userInfoCache = <span class="keyword">new</span> UserInfoCache(<span class="string">'127.0.0.1'</span>, <span class="number">6379</span>);</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">// 设置用户缓存</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">$userInfoCache-&gt;setUserInfoByMobile($userMobile, $userId, $userInfo);</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line"><span class="comment">// 获取用户缓存</span></span></pre></td></tr><tr><td class="code"><pre><span class="line">$userCacheData = $userInfoCache-&gt;getUserInfoByMobile($userMobile);</span></pre></td></tr><tr><td class="code"><pre><span class="line"></span></pre></td></tr><tr><td class="code"><pre><span class="line">var_dump($userCacheData);</span></pre></td></tr></table></figure>

<blockquote>
<p><strong>结语：通过上面三个方案的分析以及它们的优缺点，在实际运用中看项目侧重那一块，来选择合适的方案。</strong></p>
</blockquote>

      
    </div>
    <div class="article-footer">
      <blockquote class="mt-2x">
  <ul class="post-copyright list-unstyled">
    
    <li class="post-copyright-link hidden-xs">
      <strong>本文链接：</strong>
      <a href="http://jirenyou.gitee.io/blog/2019/12/21/php/php-redis-lua/" title="使用 Redis Lua脚本设置和获取多维度数据缓存(PHP示例)" target="_blank" rel="external">http://jirenyou.gitee.io/blog/2019/12/21/php/php-redis-lua/</a>
    </li>
    
    <li class="post-copyright-license">
      <strong>版权声明： </strong> 本博客所有文章除特别声明外，均采用 <a href="http://creativecommons.org/licenses/by/4.0/deed.zh" target="_blank" rel="external">CC BY 4.0 CN协议</a> 许可协议。转载请注明出处！
    </li>
  </ul>
</blockquote>


<div class="panel panel-default panel-badger">
  <div class="panel-body">
    <figure class="media">
      <div class="media-left">
        <a href="https://jirenyou.gitee.io/blog" target="_blank" class="img-burn thumb-sm visible-lg">
          <img src="/blog/images/avatar.jpg" class="img-rounded w-full" alt="">
        </a>
      </div>
      <div class="media-body">
        <h3 class="media-heading"><a href="https://jirenyou.gitee.io/blog" target="_blank"><span class="text-dark">Jirry</span><small class="ml-1x">Back end development Architecture</small></a></h3>
        <div>后端开发攻城狮，热爱互联网技术，爱学习，勤思考！</div>
      </div>
    </figure>
  </div>
</div>


    </div>
  </article>
  
    
  <section id="comments">
  	
      <div id="vcomments"></div>
    
  </section>


  
</div>

  <nav class="bar bar-footer clearfix" data-stick-bottom>
  <div class="bar-inner">
  
  <ul class="pager pull-left">
    
    <li class="prev">
      <a href="/blog/2019/12/24/php/php-bloom-filter/" title="布隆过滤器(Bloom-filter)防Redis缓存穿透应用(PHP示例)"><i class="icon icon-angle-left" aria-hidden="true"></i><span>&nbsp;&nbsp;上一篇</span></a>
    </li>
    
    
    <li class="next">
      <a href="/blog/2019/12/21/git/git-common/" title="Git 日常工作流程"><span>下一篇&nbsp;&nbsp;</span><i class="icon icon-angle-right" aria-hidden="true"></i></a>
    </li>
    
    
    <li class="toggle-toc">
      <a class="toggle-btn collapsed" data-toggle="collapse" href="#collapseToc" aria-expanded="false" title="文章目录" role="button">
        <span>[&nbsp;</span><span>文章目录</span>
        <i class="text-collapsed icon icon-anchor"></i>
        <i class="text-in icon icon-close"></i>
        <span>]</span>
      </a>
    </li>
    
  </ul>
  
  
  <!-- Button trigger modal -->
  <button type="button" class="btn btn-fancy btn-donate pop-onhover bg-gradient-warning" data-toggle="modal" data-target="#donateModal"><span>赏</span></button>
  <!-- <div class="wave-icon wave-icon-danger btn-donate" data-toggle="modal" data-target="#donateModal">
    <div class="wave-circle"><span class="icon"><i class="icon icon-bill"></i></span></div>
  </div> -->
  
  
  <div class="bar-right">
    
    <div class="share-component" data-sites="weibo,qq,wechat,facebook,twitter" data-mobile-sites="weibo,qq,qzone"></div>
    
  </div>
  </div>
</nav>
  
<!-- Modal -->
<div class="modal modal-center modal-small modal-xs-full fade" id="donateModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content donate">
      <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
      <div class="modal-body">
        <div class="donate-box">
          <div class="donate-head">
            <p>感谢您的支持，我会继续努力的!</p>
          </div>
          <div class="tab-content">
            <div role="tabpanel" class="tab-pane fade active in" id="alipay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/alipay.jpeg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开支付宝扫一扫，即可进行扫码打赏哦</p>
            </div>
            <div role="tabpanel" class="tab-pane fade" id="wechatpay">
              <div class="donate-payimg">
                <img src="/blog/images/donate/wechat.jpeg" alt="扫码支持" title="扫一扫" />
              </div>
              <p class="text-muted mv">扫码打赏，你说多少就多少</p>
              <p class="text-grey">打开微信扫一扫，即可进行扫码打赏哦</p>
            </div>
          </div>
          <div class="donate-footer">
            <ul class="nav nav-tabs nav-justified" role="tablist">
              <li role="presentation" class="active">
                <a href="#alipay" id="alipay-tab" role="tab" data-toggle="tab" aria-controls="alipay" aria-expanded="true"><i class="icon icon-alipay"></i> 支付宝</a>
              </li>
              <li role="presentation" class="">
                <a href="#wechatpay" role="tab" id="wechatpay-tab" data-toggle="tab" aria-controls="wechatpay" aria-expanded="false"><i class="icon icon-wepay"></i> 微信支付</a>
              </li>
            </ul>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>



</main>

  <footer class="footer" itemscope itemtype="http://schema.org/WPFooter">
	
	
    <ul class="social-links">
    	
        <li><a href="https://github.com/jirryji" target="_blank" title="Github" data-toggle=tooltip data-placement=top><i class="icon icon-github"></i></a></li>
        
        <li><a href="https://weibo.com/7355950025" target="_blank" title="Weibo" data-toggle=tooltip data-placement=top><i class="icon icon-weibo"></i></a></li>
        
        <li><a href="/blog/atom.xml" target="_blank" title="Rss" data-toggle=tooltip data-placement=top><i class="icon icon-rss"></i></a></li>
        
    </ul>

    <div class="copyright">
    	
        &copy; 2020 Jirry
        
        <div class="publishby">
        	Theme by <a href="https://github.com/cofess" target="_blank"> cofess </a>base on <a href="https://github.com/cofess/hexo-theme-pure" target="_blank">pure</a>.
        </div>
    </div>
</footer>
  <script src="//cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js"></script>
<script>
window.jQuery || document.write('<script src="js/jquery.min.js"><\/script>')
</script>

<script src="/blog/js/plugin.min.js"></script>


<script src="/blog/js/application.js"></script>


    <script>
(function (window) {
    var INSIGHT_CONFIG = {
        TRANSLATION: {
            POSTS: '文章',
            PAGES: '页面',
            CATEGORIES: '分类',
            TAGS: '标签',
            UNTITLED: '(未命名)',
        },
        ROOT_URL: '/blog/',
        CONTENT_URL: '/blog/content.json',
    };
    window.INSIGHT_CONFIG = INSIGHT_CONFIG;
})(window);
</script>

<script src="/blog/js/insight.js"></script>






   
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>





   
    
  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/valine"></script>
  <script type="text/javascript">
  var GUEST = ['nick', 'mail', 'link'];
  var meta = 'nick,mail,link';
  meta = meta.split(',').filter(function(item) {
    return GUEST.indexOf(item) > -1;
  });
  new Valine({
    el: '#vcomments',
    verify: false,
    notify: false,
    appId: '',
    appKey: '',
    placeholder: 'Just go go',
    avatar: 'mm',
    meta: meta,
    pageSize: '10' || 10,
    visitor: false
  });
  </script>

     







</body>
</html>